package com.automannn.atm_back.modules.codeGenerator.controller;

import com.automannn.atm_back.common.api.vo.Result;
import com.automannn.atm_back.modules.codeGenerator.entity.ColumnConfigEntity;
import com.automannn.atm_back.modules.codeGenerator.service.ColumnConfigEntityService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * (GeneratorColumnConfig)表控制层
 *
 * @author chenkaihai
 * @since 2020-07-12 16:44:05
 */
@RestController
@RequestMapping("codeGenerator/generatorColumnConfig")
@Valid
public class ColumnConfigEntityController {
    /**
     * 服务对象
     */
    @Resource
    private ColumnConfigEntityService columnConfigEntityService;

    /**
     * 分页查询所有数据
     *
     * @param page                  分页对象
     * @param generatorColumnConfig 查询实体
     * @return 所有数据
     */
    @GetMapping("/list")
    public Result<IPage<ColumnConfigEntity>> selectAll(Page<ColumnConfigEntity> page, ColumnConfigEntity generatorColumnConfig) {
        Result<IPage<ColumnConfigEntity>> result = new Result<IPage<ColumnConfigEntity>>();
        IPage<ColumnConfigEntity> pageList = columnConfigEntityService.queryAll(page, generatorColumnConfig);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable String id) {
        ColumnConfigEntity resultBean = columnConfigEntityService.queryOne(id);
        return Result.ok(resultBean);
    }

    /**
     * 新增数据
     *
     * @param generatorColumnConfig 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    public Result insert(@RequestBody ColumnConfigEntity generatorColumnConfig) {
        this.columnConfigEntityService.insert(generatorColumnConfig);
        return Result.ok("新增成功!");
    }

    /**
     * 修改数据
     *
     * @param generatorColumnConfig 实体对象
     * @return 修改结果
     */
    @PutMapping("edit")
    public Result update(@RequestBody ColumnConfigEntity generatorColumnConfig) {
        this.columnConfigEntityService.update(generatorColumnConfig);
        return Result.ok("修改成功!");
    }

    /**
     * 新增数据
     *
     * @param generatorColumnConfigList 实体对象
     * @return 新增结果
     */
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody List<ColumnConfigEntity> generatorColumnConfigList) {
        this.columnConfigEntityService.saveOrUpdate(generatorColumnConfigList);
        return Result.ok("保存成功!");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public Result delete(String id) {
        this.columnConfigEntityService.deleteById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 删除数据
     *
     * @param ids 主键
     * @return 删除结果
     */
    @DeleteMapping("deleteBatch")
    public Result deleteBatch(String ids) {
        this.columnConfigEntityService.deleteBatchByIds(ids);
        return Result.ok("批量删除成功!");
    }


}
